package numPrimeArrangements;

class Solution {
    static final int MOD = 1000000007;
    public int numPrimeArrangements(int n) {
        int count=0;//质数的数量
        for (int i = 2; i <= n; i++) {
            if(check(i)){
                count++;
            }
        }
        return (int)(factorial(count)*factorial(n-count)%MOD);
        //(10^9 + 7)
    }
    public long factorial(int n) {
        long res = 1;
        for (int i = 1; i <= n; i++) {
            res *= i;
            res %= MOD;
        }
        return res;
    }
    private boolean check(int n){
        int k=(int)Math.sqrt(n);
        for (int i = 2; i <=k ; i++) {
            if(n%i==0){
                return false;
            }
        }
        return n!=1;
    }
}
